import { Context } from "koa";

/*
 * @Author: fishroom
 * @Date: 2022-10-12 15:34:09
 * @LastEditTime: 2022-10-14 10:44:42
 * @FilePath: \koa\app\util\response.ts
 */
function success(data: any = [], message: string = "success", code: number = 0) {
  return {
    code,
    data,
    message,
  };
}
function CxtSuccess(ctx: Context, data: any = [], message: string = "success", code: number = 0) {
  return (ctx.body = {
    code,
    data,
    message,
  });
}
function error(message: string = "error", data: any = [], code: number = 1) {
  return {
    code,
    data,
    message,
  };
}
function CxtError(ctx: Context, message: string = "error", data: any = [], code: number = 1) {
  return (ctx.body = {
    code,
    data,
    message,
  });
}
export default { success, error, CxtError, CxtSuccess };
